package com.javaee.ch09.web;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;

@Validated
@RestController
@RequestMapping("/api/user")
public class UserController {

    @GetMapping("/")
    public List<User> list() {

        List<User> users = new ArrayList<>();
        // 初始化示例数据
        users.add(new User(1, "johnDoe", "john@example.com", "+1-202-555-0144"));
        users.add(new User(2, "janeSmith", "jane@example.com", "+1-202-555-0145"));
        users.add(new User(3, "bobJohnson", "bob@example.com", "+1-202-555-0146"));
        return users;
    }

    @GetMapping("/{id}")
    public User getUserById(@PathVariable int id) {
        User user = new User();
        user.setId(id);
        user.setUsername("User_" + id);
        user.setEmail("user_" + id + "@example.com");
        user.setPhone("123-456-7890");
        return user;
    }
}


@Data
@AllArgsConstructor
@NoArgsConstructor
class User {
    private int id;
    private String username;
    private String email;
    private String phone;
}


